#ifndef __EEPROM_H
#define __EEPROM_H

#include "stm32f10x.h"                  // Device header
#include "delay.h"
#include "scan.h"

#define EE_DATA_INIT    0x00
#define EE_DATA_START   EE_DATA_INIT+1

#define EE_24C02  0x00
#define EEPROM_ADDRESS (0xa0 | EE_24C02)

#define EE_WRITE    (EEPROM_ADDRESS & 0xfe)
#define EE_READ     (EEPROM_ADDRESS | 0X01)

#define EE_SCL_PIN  GPIO_Pin_6
#define EE_SDA_PIN  GPIO_Pin_7
#define EE_PIN_PORT GPIOB
#define EE_PIN_CLK  RCC_APB2Periph_GPIOB

#define EE_SCL_HIGH GPIO_SetBits(EE_PIN_PORT, EE_SCL_PIN)
#define EE_SCL_LOW  GPIO_ResetBits(EE_PIN_PORT, EE_SCL_PIN)

#define EE_SDA_HIGH GPIO_SetBits(EE_PIN_PORT, EE_SDA_PIN)
#define EE_SDA_LOW  GPIO_ResetBits(EE_PIN_PORT, EE_SDA_PIN)
#define EE_SDA_READ GPIO_ReadInputDataBit(EE_PIN_PORT, EE_SDA_PIN)

typedef struct
{
    struct
    {
		uint16_t heartbeat; //心跳间隔
        uint16_t set_item;  //16位设置项 暂保留
    } system;               //系统设置
    scanner_cmd_t scanner;
} eeprom_data_t;

void EEPROM_Init(eeprom_data_t* eeprom_data);
void EEPROM_Write(uint8_t addr, uint8_t data);
uint8_t EEPROM_Read(uint8_t addr);
void EEPROM_ContinuousWrite(uint8_t addr, uint8_t* data, uint8_t lenth);
void EEPROM_ContinuousRead(uint8_t addr, uint8_t* data, uint8_t lenth);
#endif
